//
//  YZLCarDetailTableViewCell.m
//  Car
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "YZLCarDetailTableViewCell.h"

@interface YZLCarDetailTableViewCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *driverLabel;
@property (nonatomic, strong) UILabel *engineLabel;
@property (nonatomic, strong) UILabel *transmissionLabel;
@property (nonatomic, strong) UILabel *guidePriceLabel;
@property (nonatomic, strong) UILabel *lowestPriceLabel;

@end

@implementation YZLCarDetailTableViewCell

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
        
        self.driverLabel = [[UILabel alloc] init];
        self.driverLabel.textColor = [UIColor grayColor];
        self.driverLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.driverLabel];
        
        self.engineLabel = [[UILabel alloc] init];
        self.engineLabel.textColor = [UIColor grayColor];
        self.engineLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.engineLabel];
        
        self.transmissionLabel = [[UILabel alloc] init];
        self.transmissionLabel.textColor = [UIColor grayColor];
        self.transmissionLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.transmissionLabel];
        
        self.guidePriceLabel = [[UILabel alloc] init];
        self.guidePriceLabel.textColor = [UIColor grayColor];
        self.guidePriceLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.guidePriceLabel];
        
        self.lowestPriceLabel = [[UILabel alloc] init];
        self.lowestPriceLabel.textColor = [UIColor orangeColor];
        self.lowestPriceLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.lowestPriceLabel];
        
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.nameLabel.frame = CGRectMake(10, 10, WIDTH - 20, 20);
    self.driverLabel.frame = CGRectMake(10, 40, 80, 15);
    self.engineLabel.frame = CGRectMake(90, 40, 50, 15);
    self.transmissionLabel.frame = CGRectMake(140, 40, 80, 15);
    self.lowestPriceLabel.frame = CGRectMake(10, 65, WIDTH / 2, 15);
    self.guidePriceLabel.frame = CGRectMake(WIDTH / 2, 65, WIDTH / 2, 15);
    
}

- (void)setModel:(YZLCarDetailModel *)model {
    
    if (_model != model) {
        _model = model;
    }
    
    NSDictionary *dic = [self.model.cars objectAtIndex:self.num];
    self.nameLabel.text = [dic objectForKey:@"carName"];
    self.driverLabel.text = [dic objectForKey:@"driver"];
    self.engineLabel.text = [dic objectForKey:@"engine"];
    self.transmissionLabel.text = [dic objectForKey:@"transmission"];
    NSString *str1 = @"全国最低价: ";
    self.lowestPriceLabel.text = [str1 stringByAppendingString:[dic objectForKey:@"lowestPrice"]];
    NSString *str2 = [dic objectForKey:@"guidePrice"];
    self.guidePriceLabel.text = [NSString stringWithFormat:@"(指导价: %@)", str2];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
